﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal.Other
{
    public partial class CalendarPage : DBPageBase
    {
        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID
        {
            get
            {
                return Request.QueryString["BranchID"] ?? "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbMonth.Text = DateTime.Now.Month.ToString();
                hdDate.Value = DateTime.Now.ToShortDateString();
                SetAHtml();
            }
        }

        public void SetAHtml()
        {
            DateTime dt = Convert.ToDateTime(hdDate.Value);
            
        }

        protected void DayRender(object ByVal, DayRenderEventArgs e)
        {
            if (e.Day.IsOtherMonth)
                e.Cell.Controls.Clear();
            if (!string.IsNullOrEmpty(BranchID))
            {
                DateTime date = Convert.ToDateTime(hdDate.Value);
                //绑定日期
                if (Convert.ToInt32(e.Day.DayNumberText) == 9)
                {
                }
                string calDate = PartyMeetingLecture.GetCalendarDate(date.Year, date.Month, Convert.ToInt32(e.Day.DayNumberText), BranchID);
                if (!string.IsNullOrEmpty(calDate))
                {
                    DateTime dt = Convert.ToDateTime(calDate);

                    if (!e.Day.IsOtherMonth)
                    {
                        if (DateTime.Now > dt)
                        {
                            e.Cell.BackColor = Color.FromArgb(134, 170, 0);
                        }
                        else
                        {
                            e.Cell.BackColor = Color.FromArgb(200, 55, 38);
                        }
                        e.Cell.ForeColor = Color.White;
                        e.Cell.Attributes.Add("onclick",
                            string.Format("return urlFun('MeetingLecture/MeetingCalendar.aspx?Year={0}&Month={1}&Day={2}&BranchID={3}');"
                            , date.Year, date.Month, e.Day.DayNumberText, this.BranchID));
                    }
                }
                else
                {
                    e.Cell.Attributes.Add("onclick",
                        string.Format("return false;", e));
                }
            }
            else
            {
                e.Cell.Attributes.Add("onclick",
                    string.Format("return false;", e));
            }
        }

        protected void linLeft_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(hdDate.Value))
            {
                DateTime dt = Convert.ToDateTime(hdDate.Value).AddMonths(-1);
                lbMonth.Text = dt.Month.ToString();
                calDt.TodaysDate = dt;
                hdDate.Value = dt.ToShortDateString();
                SetAHtml();
            }
        }

        protected void linRight_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(hdDate.Value))
            {
                DateTime dt = Convert.ToDateTime(hdDate.Value).AddMonths(1);
                lbMonth.Text = dt.Month.ToString();
                calDt.TodaysDate = dt;
                hdDate.Value = dt.ToShortDateString();
                SetAHtml();
            }
        }
    }
}